package repositories

import (
	"iris_product/datamodels"
	"iris_product/datasource"
)

type IUser interface {
	Select(userName string) (userInfo *datamodels.User,err error)
	Insert(user *datamodels.User)(id int64,err error)
}

type UserManager struct {
	Table string
}

func (u *UserManager) Select(userName string) (userInfo *datamodels.User, err error) {
	userInfo = &datamodels.User{}
	err = datasource.G_GormDb.Where("userName = ?",userName).First(userInfo).Error
	return
}

func (u *UserManager) Insert(user *datamodels.User) (id int64, err error) {
	if err = datasource.G_GormDb.Create(user).Error; err != nil {
		return
	}
	id = user.ID
	return
}

func NewUserManager (table string) IUser {
	return &UserManager{
		Table:table,
	}
}

